package top.mccat.common.core.controller.bk;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.mccat.common.annotation.Log;
import top.mccat.common.core.controller.BaseController;
import top.mccat.common.core.domain.AjaxResult;
import top.mccat.common.core.domain.bk.BkProduct;
import top.mccat.common.enums.BusinessType;
import top.mccat.common.service.IBkProductService;
import top.mccat.common.utils.poi.ExcelUtil;
import top.mccat.common.core.page.TableDataInfo;

/**
 * 【商品管理】Controller
 * 
 * @author ruoyi
 * @date 2022-11-06
 */
@RestController
@RequestMapping("/bk/product")
public class BkProductController extends BaseController
{
    @Autowired
    private IBkProductService bkProductService;

    /**
     * 查询【商品管理】列表
     */
    @PreAuthorize("@ss.hasPermi('bk:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(BkProduct bkProduct)
    {
        startPage();
        List<BkProduct> list = bkProductService.selectBkProductList(bkProduct);
        return getDataTable(list);
    }

    /**
     * 查询【商品名】列表
     */
    @PreAuthorize("@ss.hasPermi('bk:product:list')")
    @GetMapping("/listName")
    public TableDataInfo listName(BkProduct bkProduct)
    {
        startPage();
        List<BkProduct> list = bkProductService.selectBkProductNameList(bkProduct);
        return getDataTable(list);
    }

    /**
     * 查询【商品管理】列表
     */
    @PreAuthorize("@ss.hasPermi('bk:product:list')")
    @GetMapping("/listModel")
    public List<BkProduct> listModel(String productName)
    {
        return bkProductService.selectBkProductModelList(productName);
    }

    /**
     * 导出【商品管理】列表
     */
    @PreAuthorize("@ss.hasPermi('bk:product:export')")
    @Log(title = "【商品管理】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BkProduct bkProduct)
    {
        List<BkProduct> list = bkProductService.selectBkProductList(bkProduct);
        ExcelUtil<BkProduct> util = new ExcelUtil<BkProduct>(BkProduct.class);
        util.exportExcel(response, list, "【商品管理】数据");
    }

    /**
     * 获取【商品管理】详细信息
     */
    @PreAuthorize("@ss.hasPermi('bk:product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(bkProductService.selectBkProductById(id));
    }

    /**
     * 新增【商品管理】
     */
    @PreAuthorize("@ss.hasPermi('bk:product:add')")
    @Log(title = "【商品管理】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BkProduct bkProduct)
    {
        return toAjax(bkProductService.insertBkProduct(bkProduct));
    }

    /**
     * 修改【商品管理】
     */
    @PreAuthorize("@ss.hasPermi('bk:product:edit')")
    @Log(title = "【商品管理】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BkProduct bkProduct)
    {
        return toAjax(bkProductService.updateBkProduct(bkProduct));
    }

    /**
     * 删除【商品管理】
     */
    @PreAuthorize("@ss.hasPermi('bk:product:remove')")
    @Log(title = "【商品管理】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(bkProductService.deleteBkProductByIds(ids));
    }
}
